package com.etoak.controller;

import com.etoak.entity.Doctor;
import com.etoak.service.DoctorService;
import com.etoak.vo.PageVO;
import com.etoak.vo.ResultVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/doctor")

public class DoctorController {
    @Autowired
    DoctorService doctorService;

    @PostMapping
    public ResultVO<Object> add(@Validated @RequestBody Doctor doctor){
        doctorService.add(doctor);
        return ResultVO.success();
    }
    /**
     * 分页查询 get /doctor/list
     * @param pageNum
     * @param pageSize
     * @param doctor
     * @return
     */
    @GetMapping("/list")
    public ResultVO<PageVO<Doctor>> list(
            @RequestParam(required = false,defaultValue = "1") int pageNum,
            @RequestParam(required = false,defaultValue = "5")int pageSize,
            Doctor doctor){
        PageVO<Doctor> pageVO = doctorService.list(pageNum, pageSize, doctor);
        return ResultVO.success(pageVO);
    }

    /**
     * 更新医生
     */
    @PutMapping("/{id}")
    public ResultVO<Object> update(@PathVariable int id,@RequestBody Doctor dishes){
        doctorService.update(id,dishes);
        return ResultVO.success();
    }
    @DeleteMapping("/{id}")
    public ResultVO<Object> delete(@PathVariable int id){
        doctorService.delete(id);
        return ResultVO.success();
    }
}
